package makovo.ajax;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import makovo.data.Resources;
import makovo.entities.Applicant;
import makovo.entities.SysUser;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class UserList extends ActionSupport implements ServletRequestAware, SessionAware, Serializable {
	private static final long serialVersionUID = 1L;
	private ArrayList<SysUser> users;
	private HttpServletRequest mRequest;
	private Map<String, Object> mSession;
	private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
	private Calendar cal = Calendar.getInstance();

	public ArrayList<SysUser> getUsers() {
		return this.users;
	}

	public String getUserList() {
		try {
			Date end = new Date();

			String par = this.mRequest.getParameter("end");
			end = par.equals("") || par == null ? end : format.parse(par);

			cal.setTime(end);
			cal.add(Calendar.DATE, -30);
			Date init = cal.getTime();

			par = this.mRequest.getParameter("init");
			init = par.equals("") || par == null ? init : format.parse(par);

			users = Resources.getSystemUsers(init, end);
		} catch (Exception e) {
			e.printStackTrace();

		}

		return ActionSupport.SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.mRequest = request;
	}

	@Override
	public void setSession(Map<String, Object> sessionInfo) {
		this.mSession = sessionInfo;
	}

}
